package com.tbit.main.service.impl;

import com.tbit.main.service.MQProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service("mQProducerService")
public class MQProducerImpl implements MQProducer {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void sendDataToQueue(String queueKey, String msg) {
        try {
            log.info("queueKey=" + queueKey + ",msg=" + msg);
            amqpTemplate.send(queueKey, new Message(msg.getBytes("UTF-8"), new MessageProperties()));
        } catch (Exception e) {
            log.error("连接RabbitMQ异常", e);
        }
    }

}  